package com.vehiclemanagement.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vehiclemanagement.entity.FuelCard;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 加油卡Mapper接口
 */
@Mapper
public interface FuelCardMapper extends BaseMapper<FuelCard> {
    
    /**
     * 带条件的分页查询
     * 
     * @param page 分页对象
     * @param whereSql 条件SQL
     * @return 分页数据
     */
    @Select("SELECT * FROM fuel_card WHERE ${whereSql}")
    IPage<FuelCard> selectPageWithDeleted(Page<FuelCard> page, @Param("whereSql") String whereSql);
    
    /**
     * 检查卡号是否已存在（排除已删除的）
     * 
     * @param cardNumber 卡号
     * @return 是否存在
     */
    @Select("SELECT COUNT(*) FROM fuel_card WHERE card_number = #{cardNumber} AND del_flag = 0")
    int existsActiveCardWithNumber(@Param("cardNumber") String cardNumber);
    
    /**
     * 物理删除加油卡记录
     * 
     * @param id 加油卡ID
     * @return 影响行数
     */
    @Delete("DELETE FROM fuel_card WHERE id = #{id}")
    int deletePhysically(@Param("id") Long id);
} 